package com.qianlou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.qianlou.common.result.PagedResult;
import com.qianlou.mapper.InterviewRecordCustomMapper;
import com.qianlou.mapper.InterviewRecordMapper;
import com.qianlou.pojo.InterviewRecord;
import com.qianlou.pojo.vo.InterviewRecordVO;
import com.qianlou.service.InterviewRecordService;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 面试记录表 服务实现类
 * </p>
 *
 * @author James
 * @since 2025-04-26
 */
@Service
public class InterviewRecordServiceImpl extends ServiceImpl<InterviewRecordMapper, InterviewRecord> implements InterviewRecordService {

    @Resource
    private InterviewRecordCustomMapper interviewRecordCustomMapper;

    @Resource
    private InterviewRecordMapper interviewRecordMapper;

    @Override
    public PagedResult selectList(String realName, String mobile, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        Map<String, Object> paramsMap = new HashMap<>();
        if (StringUtils.isNotBlank(realName)) {
            paramsMap.put("realName", realName);
        }
        if (StringUtils.isNotBlank(mobile)) {
            paramsMap.put("mobile", mobile);
        }
        List<InterviewRecordVO> recordList = interviewRecordCustomMapper.selectList(paramsMap);
        return PagedResult.of(recordList, page);
    }

    @Override
    public boolean existRecordByCandidateId(String candidateId) {
        return interviewRecordMapper.exists(new QueryWrapper<InterviewRecord>()
                .eq("candidate_id", candidateId));
    }

}
